home *** CD-ROM | disk | FTP | other *** search
- /*
- * The original copyright owners of the accompanying source code files have
- * agreed to place such code into the public domain. Accordingly, anyone
- * who receives or obtains a copy of such source code is freely entitled to
- * reproduce, use and otherwise exploit such code (including the right to
- * make derivative works), at his/her own risk and expense, without any
- * obligation or liability to the original copyright owners.
- *
- * We would appreciate (but do not require) that the following message be
- * included in any derivative works:
- *
- * "Portions of this program were developed by Peter Broadwell, Rob Myers
- * and Robin Schaufler while working in Silicon Valley."
- *
- * The accompanying source code files and related documentation materials
- * are distributed on an "AS IS" basis, without any warranties or
- * guarantees of any kind. All implied warranties, including the implied
- * warranties of merchantability and of fitness for any particular purpose,
- * are expressly disclaimed.
- */
- #include <stdio.h>
- #include "gl.h" /* here for purposes of defining TRUE and FALSE only */
- #include "class.h"
- #include "classIds.h"
- #include "selectors.h"
-
- extern int maldbug;
- extern char *gfmalloc();
- extern long fishPop;
-
- #ifdef MALDEBUG
- #define Bzero(a,b) { char *q=(a), *r=(b); \
- if(maldbug) printf("bzeroing(0x%x,0x%x)\n",q,r); \
- bzero(q,r);}
- #else
- #define Bzero(a,b) bzero(a,b)
- #endif /* MALDEBUG */
-
- fcnTable instFcns[] = {
- EOTABLE
- };
-
- class instClass = {
- NULL, /* super */
- instFcns, /* fcnTable */
- sizeof(inst), /* instSize */
- INST /* classId */
- };
-
- inst instTemplate = {
- &instClass,
- 0, 0
- };
-
-
- /*
- * return TRUE if classId matches any classId up anInst's superclass chain
- */
- isSuper(anInst, classId)
- register inst *anInst;
- register int classId;
- {
- register class *aClass;
-
- if (anInst) {
- for (aClass = anInst->myClass; aClass; aClass = aClass->super) {
- if (aClass->classId == classId)
- return TRUE;
- }
- }
- return FALSE;
- }
-
- /*
- * instantiate a new member of class aClass
- */
- inst *
- instantiate(aClass)
- class *aClass;
- {
- inst *anInst;
-
- if(! aClass)
- return NULL;
- if ((anInst = (inst *)gfmalloc(aClass->instSize)) == NULL) {
- fprintf(stderr,"instantiate: gfmalloc for class %d returned NULL\n",
- aClass->classId);
- exit(-2);
- }
- Bzero(anInst, aClass->instSize);
- return anInst;
- }
-
- /*
- * clone a new instance, using anInst as the template
- */
- inst *
- clone(anInst)
- inst *anInst;
- {
- inst *newInst;
-
- if(anInst == NULL)
- return NULL;
- if((newInst = instantiate(anInst->myClass)) == NULL)
- return NULL;
- Expand(anInst);
- bcopy(anInst, newInst, anInst->myClass->instSize);
- if(isSuper(newInst,GUPPY))
- fishPop++;
- return newInst;
- }
-